﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ProvidersBox.cs" company="">
//   
// </copyright>
// <summary>
//   The providers box.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.ComponentModel;
using Systemathics.FrameWork;

namespace Systemathics.UserControls
{
    [Serializable]
    public sealed class EngineParametersBox
    {
        public EngineParametersBox()
        {
            FeesProvider = String.Empty;
            VirtualMarketProvider = String.Empty;
            LiveDataProvider = String.Empty;
            LiveOrderProvider = String.Empty;
            AckDelay = 10;
            RejectionProbability = 0.01;
            MinimumHitRatioProbability = 0.7;
            HITorTAKEProbability = 0.45;
        }

        [Browsable(true), Category("Connectivity"), 
         Description("Data Provider used to replicate Virtual Market")]
        [TypeConverter(typeof(LiveDataProviderListConverter))]
        public string VirtualMarketProvider { get; set; }

        [Browsable(true), Category("Connectivity"),
         Description("Data Provider used to Set up Live Trading")]
        [TypeConverter(typeof(LiveDataProviderListConverter))]
        public string LiveDataProvider { get; set; } 

        [Browsable(true), Category("Connectivity"),
         Description("Order Provider used to Set up Live Trading")]
        [TypeConverter(typeof (LiveOrderProviderListConverter))]
        public string LiveOrderProvider { get; set; }

        [Browsable(true), Category("Connectivity"),
        Description("Fees Provider used to Set up BackTest, Virtual or Live Trading")]
        [TypeConverter(typeof(FeesProviderListConverter))]
        public string FeesProvider { get; set; } 

        [Category("Virtual Market Parameters"), Description("Delay before receiving a market reply in Millisecondes. This feature enables to simulate market Queue participants)")]
        public int AckDelay { get; set; }

        [Category("Virtual Market Parameters"), Description("Simulate market rejection for cancel, modify or new orders. This feature enables to simulate market congestions, like fast markets drops, 0.01<= Rejection Probability <=1")]
        public double RejectionProbability { get; set; }

        [Category("Virtual Market Parameters"), Description("Means thath you will get between HitRatioProbability% and 100% of recquired Quantity you sent to the market. This feature enables to simulate iceberg orders, or peoples that are faster than youa are. 0.01<= HitRatio Probability <=1")]
        public double MinimumHitRatioProbability { get; set; }

        [Category("Virtual Market Parameters"), Description("If Your buy price is between Bid/Ask prices, you can be HITED buy the market at this price wether HitorTakeProbability event occured.(the same apply for sell orders). 0.01<= HitorTake Probability <=1")]
        public double HITorTAKEProbability { get; set; }

        #region Nested type: LiveDataProviderListConverter

        internal class LiveDataProviderListConverter : TypeConverter
        {
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true; // display drop
            }
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return true; // drop-down vs combo
            }
            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                var temp = new List<string>();
                temp.Add(string.Empty);
                temp.AddRange(ProviderFactory.GetDataProvidersName(GlobalVariables.ASSEMBLY));
                temp.AddRange(ProviderFactory.GetMixedProvidersName(GlobalVariables.ASSEMBLY));
                if (temp.Contains(StrategyMode.BackTest.ToString()))
                    temp.Remove(StrategyMode.BackTest.ToString());

                return new StandardValuesCollection(temp.ToArray());
            }
        }

        #endregion

        #region Nested type: LiveOrderProviderListConverter

        internal class LiveOrderProviderListConverter : TypeConverter
        {
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true; // display drop
            }
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return true; // drop-down vs combo
            }
            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                var temp = new List<string>();
                temp.Add(string.Empty);
                temp.AddRange(ProviderFactory.GetOrderProvidersName(GlobalVariables.ASSEMBLY));
                temp.AddRange(ProviderFactory.GetMixedProvidersName(GlobalVariables.ASSEMBLY));
                if (temp.Contains(StrategyMode.Virtual.ToString()))
                    temp.Remove(StrategyMode.Virtual.ToString());
                return new StandardValuesCollection(temp.ToArray());
            }
        }

        #endregion

        #region Nested type: LiveFeesProviderListConverter

        internal class FeesProviderListConverter : TypeConverter
        {
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true; // display drop
            }
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return true; // drop-down vs combo
            }
            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                var temp = new List<string>();
                temp.AddRange(ProviderFactory.GetFeesProvidersName(GlobalVariables.ASSEMBLY));
                return new StandardValuesCollection(temp.ToArray());
            }
        }

        #endregion
    }
}